package reign.engine;
import java.io.File;
import java.io.IOException;

import org.w3c.dom.*;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException; 

public class XMLReader{

            DocumentBuilderFactory docBuilderFactory;
            DocumentBuilder docBuilder;
            Document doc;
            NodeList nodes;

            public XMLReader(String inputFile)
            {
                try {
                docBuilderFactory = DocumentBuilderFactory.newInstance();
                docBuilderFactory.setFeature("http://apache.org/xml/features/dom/include-ignorable-whitespace",
                        false);
                docBuilder = docBuilderFactory.newDocumentBuilder();
				doc = docBuilder.parse (new File(inputFile));
				} catch (SAXException e) {
						System.err.println("Error parsing XML Error " + inputFile);
				} catch (IOException e) {
					System.err.println("Error parsing XML Error " + inputFile);
				} catch (ParserConfigurationException e) {
					System.err.println("Error parsing XML Error " + inputFile);
				}
                // normalize text representation
                doc.getDocumentElement ().normalize ();
	
            }
            
            public NodeList getPeers(String tag)
            {
                nodes = doc.getElementsByTagName(tag);
                return nodes;
            }


}